package cn.wangliang181230.boot.web.springapplicationrunlistener;

import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.time.Duration;

public class MySpringApplicationRunListener implements SpringApplicationRunListener {

	private final SpringApplication application;
	private final String[] args;

	// 必须含带有这两个参数的构造函数
	public MySpringApplicationRunListener(SpringApplication application, String[] args) {
		System.out.println("MySpringApplicationRunListener: Constructor");
		this.application = application;
		this.args = args;
	}


	public void starting(ConfigurableBootstrapContext bootstrapContext) {
		System.out.println("MySpringApplicationRunListener: starting");
	}

	public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext,
									ConfigurableEnvironment environment) {
		System.out.println("MySpringApplicationRunListener: environmentPrepared");
	}

	public void contextPrepared(ConfigurableApplicationContext context) {
		System.out.println("MySpringApplicationRunListener: contextPrepared");
	}

	public void contextLoaded(ConfigurableApplicationContext context) {
		System.out.println("MySpringApplicationRunListener: contextLoaded");
	}

	public void started(ConfigurableApplicationContext context, Duration timeTaken) {
		System.out.println("MySpringApplicationRunListener: started");
	}

//	@Deprecated
//	public void started(ConfigurableApplicationContext context) {
//	}

	public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
		System.out.println("MySpringApplicationRunListener: ready");
	}

//	@Deprecated
//	public void running(ConfigurableApplicationContext context) {
//	}

	public void failed(ConfigurableApplicationContext context, Throwable exception) {
		System.out.println("MySpringApplicationRunListener: failed");
	}
}
